import { APILX } from '@/api/requestLx'
import { getNewColumns } from '@/utils/util'
export default {
  data() {
    return {
      tableShow: false,
    }
  },
  created() {
    this.getFields()
  },
  methods: {
    async getFields() {
      let res = await APILX.formTypeExtendedFieldList({ formType: this.formType })
      if (res.code == 200 && res.result) {
        let formTypeExtendedFields = res.result || []
        let columns = []
        formTypeExtendedFields.forEach((fields) => {
          let tableHead = {
            title: fields.fieldName,
            dataIndex: 'extDataJson.' + fields.fieldKey,
            ellipsis: true,
            width: 150,
            searchIndex: 'extDataJson.' + fields.fieldKey,
            scopedSlots: {
              filterDropdown: 'searchDropdown',
              filterIcon: 'searchIcon',
            },
          }
          columns.push(tableHead)
        })
        this.columns.pop()
        this.columns = [...this.columns, ...columns]
        this.allColumn = [...this.allColumn, ...columns]
        let oldValue = localStorage.getItem(this.EntityName)
        this.columns = getNewColumns(this.allColumn, JSON.parse(oldValue), this.actionArr, this.columns)
        this.tableShow = true
      }
    },
  },
}
